/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mrp.productionPlanning.managedbean;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import mrp.productionPlanning.entity.ForecastTableEntity;
import mrp.productionPlanning.session.ForecastTableSessionBean;

/**
 *
 * @author GKnight
 */
@ManagedBean
@ViewScoped
public class CreateForecastTableManagedBean implements Serializable{
    
    private int yearName;
    
    @EJB
    private ForecastTableSessionBean forecastTableManager = new ForecastTableSessionBean();

    /** Creates a new instance of CreateForecastTableManagedBean */
    public CreateForecastTableManagedBean() {
    }
    
    public void create(ActionEvent event) throws IOException{
        setYearName(getYearName() - 1);
        List<ForecastTableEntity> forecastTableList = new ArrayList<ForecastTableEntity>();
        
        forecastTableList.add(forecastTableManager.createForecastTable("Jan",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Feb",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Mar",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Apr",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("May",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Jun",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Jul",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Aug",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Sep",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Oct",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Nov",yearName));
        forecastTableList.add(forecastTableManager.createForecastTable("Dec",yearName));
        
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("forecastTableList", forecastTableList);
        FacesContext.getCurrentInstance().getExternalContext().redirect("editForecastTable.xhtml");
    }

    /**
     * @return the yearName
     */
    public int getYearName() {
        return yearName;
    }

    /**
     * @param yearName the yearName to set
     */
    public void setYearName(int yearName) {
        this.yearName = yearName;
    }
}
